package edu.zju.gis.cky.controller;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import edu.zju.gis.cky.entity.dto.FlowDetailDTO;
import edu.zju.gis.cky.entity.dto.FlowExtentDTO;
import edu.zju.gis.cky.entity.dto.FlowMatrixDTO;
import edu.zju.gis.cky.service.LandFlowService;
import org.locationtech.jts.io.ParseException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * @author jiarui
 * @version 1.0, 2022-01-10
 */
@RequestMapping("/flow")
@RestController
public class LandFlowController {

    @Autowired
    private LandFlowService service;

    /**
     * 变化矩阵
     */
    @GetMapping("/getTable")
    public String[][] getMatrix(@RequestParam Long beginId, Long endId, String xzqh, String from, String to) {
        FlowMatrixDTO flowMatrixDTO = new FlowMatrixDTO();
        flowMatrixDTO.setBeginMetaId(beginId);
        flowMatrixDTO.setEndMetaId(endId);
        flowMatrixDTO.setXzqh(xzqh);
        flowMatrixDTO.setFrom(from);
        flowMatrixDTO.setTo(to);
        return service.getTable(flowMatrixDTO);
    }

    /**
     * 变化图斑详情
     * 1.起始数据id，2.目标数据id，Optional(3.行政区划，4.起始类型列表，5.结果类型列表(类型编号用,隔开))
     */
    @GetMapping("/getList")
    public PageInfo<JSONObject> getDetail(@RequestParam int pageNum, @RequestParam int pageSize, Long beginId, Long endId, String xzqh, String from, String to) throws ParseException, IOException {
        FlowDetailDTO flowDetailDTO = new FlowDetailDTO();
        flowDetailDTO.setBeginMetaId(beginId);
        flowDetailDTO.setEndMetaId(endId);
        flowDetailDTO.setXzqh(xzqh);
        flowDetailDTO.setFrom(from);
        flowDetailDTO.setTo(to);
        return service.getDetail(flowDetailDTO, pageNum, pageSize);
    }

    /**
     * 4.根据空间位置信息过滤变化图斑详细列表
     */
    @GetMapping("/getListByExtent")
    public PageInfo<JSONObject> getListByExtent(@RequestParam int pageNum, @RequestParam int pageSize, Long beginId, Long endId, String extent, String from, String to) {
        FlowExtentDTO flowExtentDTO = new FlowExtentDTO();
        flowExtentDTO.setBeginData(beginId);
        flowExtentDTO.setEndData(endId);
        flowExtentDTO.setExtent(extent);
        flowExtentDTO.setFrom(from);
        flowExtentDTO.setTo(to);
        return service.getListByExtent(flowExtentDTO, pageNum, pageSize);
    }
}
